//
//  DJYSegmentController.m
//  i5db
//
//  Created by iMuse on 15-5-16.
//  Copyright (c) 2015年 mySelf. All rights reserved.
//

#import "DJYSegmentController.h"
#import "DJYSegementCell.h"

@interface DJYSegmentController ()<UICollectionViewDelegateFlowLayout,UICollectionViewDataSource,UICollectionViewDelegate>

@end

@implementation DJYSegmentController
{
    NSArray * array ;
}

- (instancetype)initWithViewControllers:(NSArray *)viewControllers
{
    self = [super init];
    if (self) {
               
        // _selectedIndex = NSNotFound;
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    array = [NSArray arrayWithObjects:@"1",@"2",@"3",nil];
    
    self.view.backgroundColor = [UIColor blueColor];
    [self initView];
   
}
-(void) initView
{
    UICollectionViewFlowLayout* flowLayout = [[UICollectionViewFlowLayout alloc]init];
    flowLayout.minimumInteritemSpacing=0.f;//左右间隔
    flowLayout.minimumLineSpacing=0.f;
    
    flowLayout.scrollDirection=UICollectionViewScrollDirectionHorizontal;
   self.collectionView=[[UICollectionView alloc] initWithFrame:CGRectMake(0, 84,SCREEN_WIDTH, 44) collectionViewLayout:flowLayout];
    self.collectionView.backgroundColor = [UIColor yellowColor];
    self.collectionView.delegate    =   self;
    self.collectionView.dataSource  =   self;
    
    self.collectionView.showsHorizontalScrollIndicator=NO;
   
    [self.collectionView registerClass:[DJYSegementCell class] forCellWithReuseIdentifier:@"cell"];
   
    [self.view addSubview:self.collectionView];
}
#pragma mark---顶部的滑动试图
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
 
    return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
  
    return array.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *identify = @"cell";
   
    DJYSegementCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:identify forIndexPath:indexPath];
    if (!cell) {
        NSLog(@"不存在");
    }
   
    NSLog(@"%d",[indexPath row]);
    cell.contentView.backgroundColor = [UIColor redColor];
    return cell;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    
    NSLog(@"row = %d",[indexPath row]);
    
    
    
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}


@end
